<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
<title>选择银行卡</title>
<script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="../js/layer/layer.js"></script>
<link rel="stylesheet" type="text/css" href="../css/QuikPayment.css">
<script type="text/javascript" src="../js/flexible.js"></script>
<style type="text/css">
</style>
<script type="text/javascript">
	var openID;
	$(function() {
		openID = localStorage.getItem("ll_openID");
		$.ajax({
			url : '../llPay/getCards',
			type : 'post',
			data : {
				'openID' : openID,
				'cardType' : 'creditCard'
			},
			success : function(response) {
				if (response.length > 0) {
					var info = '';
					for (var i = 0, len = response.length; i < len; i++) {//遍历data数组
						var card_no;
						if (response[i].card_no.length < 19) {
							card_no = response[i].card_no.replace(/^(\d{6})\d{6}(\d+)/,"$1********$2");//掩码的卡号
						} else {
							card_no = response[i].card_no.replace(/^(\d{6})\d{9}(\d+)/,"$1********$2");//掩码的卡号	
						};
						info += '<div class="center" onclick="cardClick(this)">';
						info += 	'<div class="pic"><img src=""/></div>';
						info += 	'<div class="bank_name">'+response[i].bank_name+'</div>';
						info += 	'<div class="card_type">'+response[i].card_type+'</div>';
						info += 	'<div class="card_type">'+card_no+'</div>';
						info += 	'<div class="hidden">'+response[i].card_no+'</div>';
						info += '</div>';
					};
					$("#content").append(info);
				} else {
					alert("亲~您暂时没有任何的支付卡,请先添加银行卡。")
				}
				;
			}
		});

	});
	
	
	//灵活获取div中值
	function cardClick(div) {
		var loader = layer.load(2);
		var divs = div.getElementsByTagName('div');
		var card_no = divs[4].innerHTML;
		localStorage.setItem("ll_creditCard", card_no);
		
		var bankMoney = localStorage.getItem("ll_payMoney");

		$.ajax({
			url : "../llPay/order",
			type : "post",
			dataType : "json",
			data : {
				'openID' : openID,
				'card_no' : card_no,
				'totalFee' : bankMoney * 100
			},
			success : function(response) {
				layer.close(loader);
				if (response.isSuccess == "true") {
					var returnHtml = response.returnHtml;
					localStorage.setItem("data", returnHtml);
					layer.open({
						type : 1,
						content : returnHtml
					})
				} else {
					//错误信息
					layer.open({
						title : "提示",
						content : response.message
					});
				}

			}
		});
	}
	function openWindows(url) {
		window.location = url;
	}
</script>

</head>

<body>
	<div id="data" class="ui-layout-center"></div>
	<div class="all">
		<div class="head">
			<div class="bank">快捷支付</div>
		</div>
		<div class="choose">请选择银行卡</div>
		<div id="content"></div>

		<div class="bottom"
			onClick="openWindows('tianjiaxinyongka.html?sign=2')">
			<div class="add">
				<img src="../img/button_add.png" />
			</div>
			<div class="add1">
				<img src="../img/icon_add1.png" />
			</div>
			<div class="jia">添加银行卡</div>
		</div>
	</div>
</body>
</html>

